<template>
    <div class="outer">
        <div class="list" v-for="(item, index) in list" :key="index" @click="goPage('/columnIndex', item.id)">
            <div class="img">
                <img :src="item.thumb" alt="">
            </div>
            <p class="line2" style="height: 50px;"><b>【{{ item.title }}】</b>{{ item.intro }}</p>

            <div class="bom">
                <div class="y2">
                    <span @click.stop="goPage('/association/youping', item.user_id)"> {{ item.user_nickname
                    }}</span>
                </div>
                <div class="y2">
                    <i class="iconfont">&#xe611;</i>
                    <span>{{ item.saves }}</span>
                </div>
                <div class="y2">
                    <i class="iconfont">&#xe640;</i>
                    <span>{{ item.likes }}</span>
                </div>

                <!-- <div class="y2">
                    <i class="iconfont">&#xe61e;</i>
                    <span>{{ item.views }}</span>
                </div> -->

            </div>

        </div>
        <el-empty style="margin:0 auto" description="没有内容了" v-if="list.length == 0"></el-empty>

    </div>

</template>
<script>

export default {
    data() {
        return {
            list: [],
            dialogVisible: false,
            form: { type: '' },
            pageNum: 1,
            totalPage: 1,
            loading: false,
            user_id: 0,

        }
    },

    computed: {
        keyword() {
            return this.$route.query.keyword
        },
        id() {
            return this.$route.query.id
        }
    },

    watch: {
        keyword(n) {
            this.pageNum = 1
            this.getList()
        },
    },
    mounted() {
        let uid = this.$route.query.id
        if (uid) {
            this.user_id = uid
            this.pageNum = 1
        }

        this.getList()

        window.addEventListener('scroll', this.handleScroll); // 监听滚动事件

    },
    beforeDestroy() {
        window.removeEventListener('scroll', this.handleScroll); // 移除监听
    },

    methods: {
        goPage(url, id) {
            this.$router.push({
                path: url,
                query: {
                    id
                }
            })
        },
        getList() {
            this.loading = true
            let params = {
                page: this.pageNum,
                user_id: this.user_id,
                keyword: this.keyword
            }
            this.$api.getUCList(params).then(res => {
                if (res.data.code == 1) {
                    if (this.keyword) {
                        this.list = []
                    }

                    this.totalPage = res.data.data.last_page
                    this.list = this.list.concat(res.data.data.data);
                    this.loading = false
                }

            })
        },

        load() {
            console.log("处理触底");
            var page = this.pageNum
            //如果请求未结束就返回不连续请求
            if (this.loading) {
                return
            }
            //数据请求完成无更多数据时
            if (page >= this.totalPage) {
                return false;
            }
            page = parseInt(page) + 1
            this.pageNum = page
            this.getList()
        },
        onsubmit() {
            console.log(this.form);

        },
        handleScroll() {
            const scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
            const windowHeight = window.innerHeight;
            const scrollHeight = document.documentElement.scrollHeight || document.body.scrollHeight;
            // 判断是否滚动到底部
            if (scrollTop + windowHeight >= scrollHeight - 20) {
                this.load()
            }
        },
    }
}
</script>
<style lang="scss" scoped>
.outer {
    display: flex;
    flex-wrap: wrap;
    padding-bottom: 20px;
}

.dialog-header {
    font-weight: bold;
    font-size: 22px;
}

.dialog-footer {
    font-weight: bold;
    font-size: 22px;
    display: flex;
    justify-content: center;
    align-items: center;

    button {
        margin: 0 50px;
        width: 140px;
        height: 50px;
        font-size: 16px;
        line-height: 50px;
        padding: 0;
    }
}

.list {
    cursor: pointer;
    width: 330px;
    margin-right: 25px;
    margin-bottom: 80px;
    border-radius: 10px;
    overflow: hidden;

    &:nth-child(4n) {
        margin-right: 0;
    }

    .img {
        width: 330px;
        height: 331px;
        justify-content: center;
        align-items: center;
        display: flex;
        // background-color: #E5E5E5;
        flex-direction: column;
        border-radius: 10px;
        overflow: hidden;

        img {
            width: 330px;
            height: 330px;
            object-fit: cover;
        }

        i {
            font-size: 100px;
            color: #999;
            border: 1px dashed #999;
            margin-bottom: 39px;
        }

        span {
            font-weight: 400;
            font-size: 24px;
            color: #666666;
        }
    }

    >p {
        font-weight: 400;
        font-size: 18px;
        color: #000000;
        margin: 24px 0 20px;
    }

    .bom {
        display: flex;
        justify-content: space-between;
        align-items: center;

        .y2 {
            padding: 0 10px;

            >div {
                display: flex;
                align-items: center;
            }

            i {
                font-size: 16px;
                margin-right: 5px;
            }

            span {
                font-size: 14px;
                color: #999;
            }
        }

        .collect {
            font-weight: 400;
            font-size: 16px;
            color: #999999;
        }
    }
}
@media screen and (max-width:768px) {
    .outer{
      .list{
        border: 1px solid #ccc;
            border-radius: 10px;
        padding: 10px;
        width: 100%;
        height: 140px;
        display: flex;
        position: relative;
        .img{
            flex-shrink: 0;
            width: 120px;
            height: 120px;
            img{
                width: 100%;
                height: 100%;
            }
        }
        >p{
            font-size: 14px;
            margin-left: 10px;
            max-height: 80px;
            line-height: 20px;
            -webkit-line-clamp: 4;
            line-clamp: 4;
            height: auto !important;
        }
        .bom{
            position: absolute;
            bottom: 10px;
            left: 140px;
            width: calc(100% - 140px);
            justify-content: flex-start;
            .y2{
                margin-right: 10px;
                span{
                    font-size: 12px;

                }
                i{
                    font-size: 12px;
                    margin-right: 5px;
                }
            }
        }
      }  
    }
}
</style>